#ifndef CHATSERVICE_H
#define CHATSERVICE_H

#include <muduo/net/TcpConnection.h>
#include <iostream>
#include <unordered_map>
#include <functional>
#include "json.hpp"
#include "public.hpp"
using json = nlohmann::json;

//第一个参数是 对方的TcpConnection信息，第二个参数是对方发过来的完整信息，第三个参数是 时间
using handler = std::function<void(const muduo::net::TcpConnectionPtr&,const json& ,muduo::Timestamp)>;

class ChatService
{
public:
   static ChatService* instence;

   ChatService* getMegType()
   {
       if(instence == nullptr)
       instence = new ChatService();

       return instence;
   }

   void Destory()
   { delete instence;}

   static void Login(const muduo::net::TcpConnectionPtr& conn,const json& js,muduo::Timestamp time)
   {}
   static void Register(const muduo::net::TcpConnectionPtr& conn,const json& js,muduo::Timestamp time)
   {}
private:
    ChatService()
    {
        _MegHandlerMap.insert(std::make_pair(LOGIN_MSG,Login));
        _MegHandlerMap.insert(std::make_pair(REG_MSG,Register));      
    }
private:
   //将MegType类设置为单例模式类
   std::unordered_map<int,handler> _MegHandlerMap; 
};



#endif 